<?php
/**
 * Created by Zhy
 * User: Zhy
 * Date: 2022/6/23
 * Time: 15:40
 */

namespace app\admin\controller;


use think\Db;

class Classorder extends Base
{
    /**
     * 课程兑换码列表
     * @return mixed|\think\response\Json
     */
    public function index(){
        if(request()->isAjax ()){
            $user_name = input('user_name');
            $user_phone = input('user_phone');
            $co_number = input('co_number');
            $co_pay_type = input('co_pay_type');
            $where = [];
            if(isset($user_name) && $user_name != ''){
                $where['user_username'] = ['like', '%' . $user_name . '%'];
            }
            if(isset($user_phone) && $user_phone != ''){
                $where['user_phone'] = ['like', '%' . $user_phone . '%'];
            }
            if(isset($co_number) && $co_number != ''){
                $where['co_number'] = ['like', '%' . $co_number . '%'];
            }
            if(isset($co_pay_type) && $co_pay_type != ''){
                $where['co_pay_type'] = $co_pay_type;
            }

            $Nowpage = input('page') ? input('page') : 1;
            $limits = input("limit") ? input("limit") : 100;
            $count = Db::name('class_order')
                ->join('up_u_user', 'user_id = co_user_id', 'LEFT')
                ->join('up_class', 'class_id = co_class_id', 'LEFT')
                ->where($where)
                ->count();// 获取总条数
            $lists = Db::name('class_order')
                ->join('up_u_user', 'user_id = co_user_id', 'LEFT')
                ->join('up_class', 'class_id = co_class_id', 'LEFT')
                ->where($where)
                ->field('co_id, co_number, co_is_pay, co_total_price, co_pay_type, co_class_code, 
                co_create_time, class_title, user_username, user_phone')
                ->order('co_create_time desc')
                ->page($Nowpage,$limits)
                ->select();

            return json(['code' => 220, 'msg' => '', 'count' => $count, 'data' => $lists]);
        }
        return $this->fetch();
    }
}